﻿namespace OleDbDAL.Systems
{
    using DBUtility;
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using System.Text;

    public class LogisticsApp : ILogistics
    {
        private string dbname = "Systems";

        public void Add(LogisticsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_Logistics(");
            builder.Append("ChainNum,logisticsName,logisticsTel,logisticsHandSet,logisticsInt,logisticsWebName,IsVtag");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.ChainNum + ",");
            builder.Append("'" + model.logisticsName + "',");
            builder.Append("'" + model.logisticsTel + "',");
            builder.Append("'" + model.logisticsHandSet + "',");
            builder.Append("'" + model.logisticsInt + "',");
            builder.Append("'" + model.logisticsWebName + "',");
            builder.Append("" + model.IsVtag + "");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int LogisticsId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_Logistics ");
            builder.Append(" where LogisticsId=" + LogisticsId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_Logistics ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by LogisticsId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "LogisticsId", "T_Logistics", swhere);
        }

        public LogisticsEnt GetModel(int LogisticsId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select LogisticsId,ChainNum,logisticsName,logisticsTel,logisticsHandSet,logisticsInt,logisticsWebName,IsVtag from T_Logistics ");
            builder.Append(" where LogisticsId=" + LogisticsId);
            LogisticsEnt ent = new LogisticsEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.LogisticsId = LogisticsId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["ChainNum"].ToString() != "")
                {
                    ent.ChainNum = int.Parse(table.Rows[0]["ChainNum"].ToString());
                }
                ent.logisticsName = table.Rows[0]["logisticsName"].ToString();
                ent.logisticsTel = table.Rows[0]["logisticsTel"].ToString();
                ent.logisticsHandSet = table.Rows[0]["logisticsHandSet"].ToString();
                ent.logisticsInt = table.Rows[0]["logisticsInt"].ToString();
                ent.logisticsWebName = table.Rows[0]["logisticsWebName"].ToString();
                if (table.Rows[0]["IsVtag"].ToString() != "")
                {
                    ent.IsVtag = int.Parse(table.Rows[0]["IsVtag"].ToString());
                }
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_Logistics ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "LogisticsId");
        }

        public void Update(LogisticsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_Logistics set ");
            builder.Append("ChainNum=" + model.ChainNum + ",");
            builder.Append("logisticsName='" + model.logisticsName + "',");
            builder.Append("logisticsTel='" + model.logisticsTel + "',");
            builder.Append("logisticsHandSet='" + model.logisticsHandSet + "',");
            builder.Append("logisticsInt='" + model.logisticsInt + "',");
            builder.Append("logisticsWebName='" + model.logisticsWebName + "',");
            builder.Append("IsVtag=" + model.IsVtag + "");
            builder.Append(" where LogisticsId=" + model.LogisticsId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

